package com.dwy2002.product.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.dwy2002.enums.rabbit.DlxRabbitConstants.DLX_EXCHANGE;
import static com.dwy2002.enums.rabbit.DlxRabbitConstants.DLX_ROUTING_KEY;
import static com.dwy2002.enums.rabbit.ProductRabbitConstants.*;

/**
 * 商品Rabbit配置类
 *
 * @author 杜伟毅
 * @version 1.0
 * @since 2025/03/23
 */
@Configuration
public class ProductRequestRabbitConfig {
    //对列声明
    @Bean
    public Queue productRequestQueue() {
        return QueueBuilder.durable(PRODUCT_REQUEST_QUEUE)
                .deadLetterExchange(DLX_EXCHANGE) // 绑定死信交换机
                .deadLetterRoutingKey(DLX_ROUTING_KEY)
                .build();
    }

    //交换机声明
    @Bean
    public DirectExchange productRequestExchange() {
        return new DirectExchange(PRODUCT_REQUEST_EXCHANGE);
    }

    //绑定声明
    @Bean
    public Binding productRequestBinding() {
        return BindingBuilder.bind(productRequestQueue())
                .to(productRequestExchange())
                .with(PRODUCT_REQUEST_ROUTING_KEY);
    }
}
